package com.atguigu.gulimall.minio.file.controller;

import com.atguigu.common.utils.R;
import com.atguigu.gulimall.minio.file.service.MinIoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("minio/upload")
@Slf4j
public class MinIoController {

    @Autowired
    private MinIoService minIoService;
      /**
     * 上传文件
     */
     @PostMapping("/upload_picture")
    public R uploadPicture(MultipartFile file){
         log.info("file:{}",file);
         if(file == null || file.getSize() == 0){
            return R.error(501, "上传文件不能为空");
         }
        String fileId =minIoService.uploadPicture(file);
         return R.ok().put("fileId",fileId);
    }
}
